package com.neu.cpspgateway.service.impl;

import com.neu.cpspgateway.dao.AuthorityMapper;
import com.neu.cpspgateway.pojo.AuthorityUser;
import com.neu.cpspgateway.service.AuthorityService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;

@Service
public class AuthorityServiceImpl implements AuthorityService {

    @Autowired
    AuthorityMapper authorityMapper;

    @Override
    public AuthorityUser selectAuthorityAndUserByUserId(Integer userId){
        return authorityMapper.selectAuthorityAndUserByUserId(userId);
    }

    @Override
    public List<AuthorityUser> selectAuthorityUserBySubSystemId(Integer subSystemId){
        List<Integer> userId = authorityMapper.selectUserIdBySubSystem(subSystemId);
        List<AuthorityUser> authorityUser = new ArrayList<AuthorityUser>();

            for(int i=0;i<userId.size();i++){

                assert authorityUser != null;
                authorityUser.add(authorityMapper.selectAuthorityAndUserByUserId(userId.get(i)));
            }
            return authorityUser;

    }

    public List<AuthorityUser> selectAuthorityUserByNameAndSubSystemId(String name,Integer subSystemId){
        List<AuthorityUser> authorityUser = new ArrayList<AuthorityUser>();
        authorityUser.add(authorityMapper.selectAuthorityAndUserByUserId(authorityMapper.selectUserIdByNameAndSubSystem(name,subSystemId)));
        return authorityUser;
    }

    @Override
    public int updateLookAuthorityByUserId(Integer userId,Boolean lookAuthority){
        return authorityMapper.updateLookAuthorityByUserId(userId,lookAuthority);
    }

    @Override
    public int updateEditAuthorityByUserId(Integer userId,Boolean editAuthority){
        return authorityMapper.updateEditAuthorityByUserId(userId,editAuthority);
    }
}
